import { ADD, DELETE } from "./constant";

const store = 0;
/**
 * Reducers 接收 prevState 、action 两个参数，对状态进行加工后返回新状态
 *      - prevState为上一次的State，首次调用为undefined，所以可以设置默认值
 */
export default function counterReducer(prevState = store, { type, data }) {
  switch (type) {
    case ADD:
      return prevState + data;
    case DELETE:
      return prevState - data;
    default:
      return prevState;
  }
}
